<!-- 请示决策会议弹框 做条件判断显示or隐藏 -->
<template>
  <div>
    <el-dialog
      v-model="state.centerDialogVisible"
      :title="state.type + '请示决策会议'"
      width="50%"
      align-center
      class="dialogStyle"
    >
      <el-form
        :model="formInline"
        ref="formRef"
        :rules="rules"
        class="demo-form-inline"
        label-width="160px"
      >
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="审批单编号" class="">
              <el-input disabled v-model="formInline.flowId" />
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="state.type == '查看'">
            <el-button class="btn button_edit" @click="toPath">查看审批流程</el-button>
          </el-col>
          <el-col :span="12">
            <el-form-item label="关联项目集" class="">
              <el-input disabled v-model="formInline.projectSetName" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目名称" class="">
              <el-input disabled v-model="formInline.projectName" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目编号" class="">
              <el-input disabled v-model="formInline.projectId" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目分类" class="">
              <el-input disabled v-model="formInline.projectType" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="业务单元" class="">
              <el-input disabled v-model="formInline.businessUnitName" />
              <!-- <el-select
                v-model="formInline.businessUnit"
                clearable
                disabled
                placeholder="业务单元"
              >
                <el-option
                  v-for="item in businessUnitArr"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select> -->
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="计划实施时间范围" class="">
              <el-date-picker
                v-model="formInline.predictStartTime"
                type="daterange"
                disabled
                range-separator="-"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目位置" class="">
              <el-input disabled v-model="formInline.projectRegionName" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目详细地址" class="" prop="">
              <el-input disabled v-model="formInline.projectStreetName" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="拟计划总投额" class="">
              <el-input disabled v-model="formInline.projectAmount" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目类型">
              <el-select
                v-model="formInline.projectCategory"
                clearable
                disabled
                placeholder="项目类型"
                @change="streerTypeChange"
              >
                <el-option value="1" label="公司自建"></el-option>
                <el-option value="2" label="政府投资"></el-option>
                <el-option value="3" label="代建项目"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目立项部门" class="">
              <el-input disabled v-model="formInline.projectDepartment" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目负责人" class="">
              <el-input disabled v-model="formInline.departmentUserName" />
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="state.tabId!=1">
            <el-form-item label="项目编码" class="">
              <el-input disabled v-model="formInline.projectCode" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="会议名称" class="" prop="meetingName">
              <el-input
                :disabled="state.disabled"
                v-model="formInline.meetingName"
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item :label="state.tabId==='1'?'决策意见':'申请原因'" class="" prop="applicationCase">
              <el-input
                :disabled="state.disabled"
                v-model="formInline.applicationCase"
                type="textarea"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <span class="dialog-footer" v-if="!state.disabled">
          <el-button @click="state.centerDialogVisible = false" class="button_cancel2">取消</el-button>
          <el-button @click="bfbfProjectApprovalFormHandel" class="button_view">
            送审
          </el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
<script setup>
import { projectConfigApi, department, publicProject } from "@/api/project";
import { businessUnitArr } from "@/common/dict/dictCollect.js";

import { ref, reactive, onMounted } from "vue";
import {
	ElDialog,
	ElForm,
	ElFormItem,
	ElMessage,
	ElRow,
	ElCol,
} from "element-plus";

let state = reactive({
	centerDialogVisible: false,
	disabled: false,
	departmentOptions: [],
	tabId:'',
});

const rules = {
	meetingName: [{ required: true, message: "请输入会议名称", trigger: "blur" }],
	applicationCase: [
		{ required: true, message: "请输入申请原因", trigger: "blur" },
	],
};

const formInline = reactive({});

// 状态 1 待审核 2审核成功 3审核驳回
let projectApplyStatus = null;

const getBfbfProjectApprovalFormView = (row) => {
	// projectApplyStatus = row.projectApplyStatus;
	projectApplyStatus = 3;
	console.log("approvalFormId", row.approvalFormId);

	projectConfigApi.bfProjectApprovalFormView(row.projectId).then((res) => {
		if (res.code == 200) {
			for (let key in res.data) {
				if (res.data[key] !== null) {
					if (key == "predictStartTime") {
						formInline[key] = [res.data[key], res.data["predictEndTime"]];
					} else {
						formInline[key] = res.data[key];
					}
				}
				formInline.projectId = row.projectId;
			}
		}
	});
};
const topicOptions = [
	{ value: "0", label: "三重一大" },
	{ value: "1", label: "非三重一大" },
];
let projectTypeList = reactive([]);
const getpublicProject = () => {
	publicProject.getProjectTypeVo("").then((res) => {
		if (res.code == 200) {
			projectTypeList = res.data;
		}
	});
};
const formRef = ref(null);
let url = "bfProjectApprovalFormAdd";
const bfbfProjectApprovalFormHandel = () => {
	//   if (projectApplyStatus == 1) {
	//     url = 'bfProjectApprovalFormAdd'
	//   } else if (projectApplyStatus == 3) {
	//     url = 'bfProjectApprovalFormEdit'
	//   }
	formRef.value.validate((valid, fields) => {
		if (valid) {
			projectConfigApi[url](formInline).then((res) => {
				if (res.code == 200) {
					state.centerDialogVisible = false;
					ElMessage.success("操作成功!");
				}
			});
		}
	});
};
//获取所有部门信息
const getdepartmentList = () => {
	department.getAllDepartments().then((res) => {
		state.departmentOptions = res?.data || [];
	});
};

const toPath = () => {
	window.open(formInline.routeUrl);
};
onMounted(() => {
	getdepartmentList();
	getpublicProject();
});
defineExpose({
	state,
	getBfbfProjectApprovalFormView,
});
</script>
<style lang="scss" scoped>
.el-dialog__body .el-form {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-around;
}
.el-form-item,
.el-select {
	width: 100% !important;
}

.btn {
	margin-left: 140px;
}
</style>
<style lang="scss" scoped>
@import '@/views/constructionProjectManage/static/dialog.scss';
</style>
